package com.tiwi.gmbdr;

import com.tiwi.gmbdr.OpenHelper.QuestionOpenHelper;
import com.tiwi.gmbdr.constant.Global;
import com.tiwi.gmbdr.model.Question;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.AsyncTask;

public class LoadSoalTask extends AsyncTask<Void, Void, String> {

	private ProgressDialog progressDialog;
	private Activity activity;
	private String messageWait;

	public LoadSoalTask(Activity activity) {
		this.activity = activity;
		this.messageWait = "Updating...";

	}

	@Override
	protected void onPreExecute() {
		progressDialog = ProgressDialog.show(this.activity, "",
				this.messageWait, true);

	}

	@Override
	protected String doInBackground(Void... arg0) {

		// disini seharusnya ada fungsi bagaimana caranya 
		// menampilkan soal secara random
		
		QuestionOpenHelper questionOpenHelper = new QuestionOpenHelper(activity);
		
		Question bean = questionOpenHelper.getOneQuestions("1"); 
	
		Global.currentQuestion = bean;
		
		
		
		return null;
	}

	@Override
	protected void onPostExecute(String result) {
		if (progressDialog.isShowing()) {
			try {
				progressDialog.dismiss();
			} catch (Exception e) {
			}
		}
		
		activity.startActivity(new Intent(activity, QuestionsActivity.class));
		activity.finish();


	}

}
